* Generate Figure B.3 and Table B.1 (Sensitivity with respect to depreciation cutoffs)
use "Empirics/AggregateData/Database/output/Database.dta", clear
cd "Empirics/AggregateData/Analysis"
set more off
graph drop _all

* 15% depreciation cutoff (left panel of Figure B.3)
* Locals
local titleA `" "15% Depreciation Cutoff" "'
local GraphsByEpi=0 
local pretrends =0 

*. Where to store results
local outputfolder "../../../Output"

*. Set Window length
local windowstart=-4
local windowend=8

*. Minimum # years events need to be apart
local apart=4

*. Create variables & Declare panel
qui do "Analysis_dofiles/CreateVars.do" `outputfolder'

*. Identify Large Devaluations
gen largeDevaluation = 1 if gER<=-0.15 & acceER<=-0.10 & gRER<=0  // NER threshold to 15%

* Ensure events are X years apart, where X is given by `apart'
qui do "Analysis_dofiles/Apart.do" `apart' `outputfolder' `windowstart' `windowend' 

* Additional sample adjustments
qui do "Analysis_dofiles/Adjustments.do"

*. Extract list of events and number of events for each country
qui do "Analysis_dofiles/ExtractList.do"

sort id year
*. Create more variables:
qui do "Analysis_dofiles/CreateMoreVars.do"

* Regressions for Table B.1	(top panel)
do "Analysis_dofiles/Regressions_Sensitivity.do" `outputfolder' `pretrends'
esttab One Two Three Four Five Six Seven Eight Nine using "../../../Output/TableB1_A.csv", label keep(deva) b(%9.2f) se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01) replace
* Figure B.3 (left panel)
qui do "Analysis_dofiles/Produce_FB3.do" `outputfolder' `GraphsByEpi' `windowstart' `windowend' `titleA'
graph save "temp/F2_15", replace

* 25% depreciation cutoff (rigth panel of Figure B.3)
clear all
use "../Database/output/Database.dta", clear
set more off
graph drop _all

* Locals
local titleB `" "25% Depreciation Cutoff" "'
local GraphsByEpi=0

*. Where to store results
local outputfolder "../../../Output"

*. Set Window length
local windowstart=-4
local windowend=8

*. Minimum # years events need to be apart
local apart=4 // baseline

*. Create variables & Declare panel
qui do "Analysis_dofiles/CreateVars.do" `outputfolder'

*. Identify Large Devaluations
gen largeDevaluation = 1 if gER<=-0.25 & acceER<=-0.10 & gRER<=0  // NER threshold to 25%

* Ensure events are X years apart, where X is given by `apart'
qui do "Analysis_dofiles/Apart.do" `apart' `outputfolder' `windowstart' `windowend' 

* Additional sample adjustments
qui do "Analysis_dofiles/Adjustments.do"

*. Extract list of events and number of events for each country
qui do "Analysis_dofiles/ExtractList.do"

sort id year

*. Create more variables:
qui do "Analysis_dofiles/CreateMoreVars.do"

* Regressions for Table B.1	(top panel)
do "Analysis_dofiles/Regressions_Sensitivity.do" `outputfolder' `pretrends'
esttab One Two Three Four Five Six Seven Eight Nine using "../../../Output/TableB1_B.csv", label keep(deva) b(%9.2f) se stats(r2 N) star(* 0.1 ** 0.05 *** 0.01) replace

* Figure B.3 (left panel)
qui do "Analysis_dofiles/Produce_FB3.do" `outputfolder' `GraphsByEpi' `windowstart' `windowend' `titleB'
graph save "temp/F2_25", replace

* Put Figure B.3 together and save
graph combine "temp/F2_15.gph" "temp/F2_25.gph", graphregion(color(white)) ycommon xsize(8)
graph export "../../../Output/FB3.pdf", replace

cd ../../..
